<?php
$db = new Database;
$auth = Auth::getAuth('current_user');
$user_id = $auth['id'];
$company_id = $auth['company_id'];
$user_groupType = $auth['role_type'];
$user_group = $auth['role'];
$userLevel = $auth['userlevel_id'];
$userPositionID = $auth['position_id'];
$userName = $auth['firstname'] . " " . $auth['lastname'];
$getPosition = $db->query("SELECT * FROM tbposition where id = '$userPositionID'","row");
$timezone = "Asia/Manila";
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);

?>
    <div class="drag" style="position: fixed;left: 0;bottom: 0;top:0;z-index:1000;margin-top:2px;margin: 32px 0px 0px 0px;border-right: 1px solid #ddd; width: 30px; min-height: 100%;background-color: #fff;">
        <?php
        $userAvatarMessage = $db->query("SELECT * FROM tbuser WHERE online='1' and id!='$user_id' and company_id ='$company_id'","array");
        foreach($userAvatarMessage as $imageData){
            $name = $imageData['firstname'].'-'.$imageData['lastname'];
            echo "<a href=\"javascript:void(0)\" onclick=\"javascript:chatWith('".$imageData['firstname']."')\">";
            //echo "<a class='openChat'>";
        echo myAvatar($imageData['extension'],$imageData['id'],"30","30","border:1px solid #ddd;");
            echo "</a>";
            //echo '</a>';
        }
        ?>
    </div>
    <div class="body_contents">
        <div id="modalBox" style="display: none; position: fixed; opacity: 1; z-index: 11000; left: 50%; margin-left: -330px; top: 80px;">
       <!--<img src="/images/icon/login.png" width="24" height="24"/>
       Sign In to Formalistic-->
      
        </div>
        <div id="modalBg" style="display: none; opacity: 0.5;"></div>
        <!-- Content Dashboard-->
        <!-- For Messaging to selected person -->
        <div style="float: left;width: 100%;">
            <div style="float: left;height: 20px;width: 100%;padding: 2px 0px 2px 2px;border-bottom: 1px solid #ddd;">
                Select user to start a messaging.
                <label class="hrefPostAction checkboxforMB pull-right display">
                <input type="checkbox" name="selectAll" class="selectAll"> Select All
                </label>
                
            </div>
            <br><br><br>
            <ul id="mycarousel" class="jcarousel-skin-tango">
                <?php
                    $db = new Database();
                    $userAvatarMessage = $db->query("SELECT * FROM tbuser where company_id = '$company_id' and id!='$user_id' and status = 1 and is_active = 1","array");
                    foreach($userAvatarMessage as $imageData){
                        echo "<li class='cursor' title='".$imageData['firstname']. " " .$imageData['lastname']."'>
                                <a rel='modalBg' name='test' href='#modalBox' class='modal' data-id='".$imageData['id']."' data-action='message' style='color: #fff;'>"
                                    .myAvatar($imageData['extension'],$imageData['id'],"50","50","none").
                                "</a><center><input type='checkbox' name='singleSelectAll[]' data-id='".$imageData['id']."' class='singleSelectAll messageCheckBox display' style='margin-bottom:15px;'/><center>
                            </li>";
                    }
                ?>
            </ul>
        </div>
        <script>
            $(".EgroupMessage").live("click", function(){
                $(".messageCheckBox").show();
                $(this).hide();
                $(".DgroupMessage").show();
                $(".ViewMessageBox").show();
                $(".checkboxforMB").show();
            });
            $(".DgroupMessage").live("click", function(){
                $(".messageCheckBox").hide();
                $(".messageCheckBox, .selectAll").attr("checked",false);
                $(this).hide();
                $(".EgroupMessage").show();
                $(".ViewMessageBox").hide();
                $(".checkboxforMB").hide();
                // Remove Unchecked ID in the textbox
                var list = $(':checkbox[name="singleSelectAll[]"]:checked').map(function(){
                return $(this).attr("data-id");
                }).get().join(',');
                $(".viewNewMB").attr("data-id",list);
                
            });
        </script>
    </div>
    <!-- For Messaging -->
    <div class="body_contents" style="margin-bottom: 20px;">
        <div id="panel-frame"> 
            <div class="panel"> 
               
            </div> 
        </div> 
      
        <div class="leftMessagePanel">
            <!-- Load Message -->
        </div>
        <div style="float: left;width: 335px;height:500px;text-align: center;border-right:1px solid #ddd;">
            <div style="margin-top:200px;color:#ccc;">
            <label style="font-size:15px;">No Conversation Selected</label> <br/>
            Select message from the left <br/>
            side to view your conversation
            </div>
        </div>
        <div style="float: left;width: 260px;height:500px;">
            <div style="float: left;width: 250px;height:500px;padding: 5px;">
            <button title="" class="button-btn inboxMessage"><i class="icon-inbox"></i>Inbox (<label class="noti-message"></label>)</button>
            <button title="" class="button-btn EgroupMessage"><i class="icon-th-list"></i>Group Message</button>
            
            <button title="" class="button-btn ViewMessageBox display"><i class="icon-inbox"></i>
                <a rel='modalBg' name='test' href='#modalBox' class='modal viewNewMB'  data-id='' style='color: #848383;' data-action='message'>
                    Message Box
                </a>
            </button>
            
                        <button title="" class="button-btn deleteConversation" data-id=""><i class="icon-ok"></i>Enable Delete</button>
                        <button title="" class="button-btn cancenDeleteConversation display"><i class="icon-remove"></i>Cancel Delete</button>
                        
            <br /><br />
            <div class="hr"></div>
            <button title="" class="button-btn selectAllDeleteMessage display" data-id=""><input type="checkbox" />Select All</button>
            <button title="" class="button-btn deleteMessageFromDB display" data-message-id="" data-id=""><i class="icon-trash"></i>Delete Message</button>
            <button title="" class="button-btn DgroupMessage display"><i class="icon-th-list"></i>Cancel Message</button>
            
            
            <br /><br />
            <div class="hr"></div>
            <span class="fontGray">Sent Message History</span>
            <br />
            <div style="float: left;height: 300px;width: 100%;">
                <?php
                $getNotiSent = $db->query("SELECT * FROM tbsend_message WHERE sender='$user_id' ORDER BY id DESC LIMIT 0,9","array");
                foreach($getNotiSent as $sent){
                    echo '<div style="float: left;width: 100%;font-size:10px;height: 30px;border-bottom: 1px solid #ddd;">
                            <div style="float: left;margin-top: 10px;">'.$userName.' send a message to specific user</div>
                        </div>';
                }
                ?>
            </div>
        </div>
        </div>
    </div>
    <div class="loadRequest" style="display: none"></div>
    <script>
        setActivNav("home");
        $('#mycarousel').jcarousel();
        jQuery("label.timeago").timeago();  
    </script>